define([
	'jquery',
	'underscore',
	'backbone',
	'baseView',
	'text!forum/login/login.html',
	'js/myUtil.js'
], function($, _, Backbone, BaseView, tpl, myUtil) {
	return BaseView.extend({
		render: function(cb) {
			// console.log('test render, qs=%s', qs);
			var tmpl = _.template(tpl);
			$(this.el).html(tmpl);
			if (!$(this.el).is(":visible")) // if hide then show
				this.show();
			cb && cb();
		},

		events: {
			"submit #login": "doLogin",
			"click #toRegister": "toRegister",
			"click .ButtonAbc": "doLogin2" // works fine, form
		},

		doLogin: function(event) {
			event.preventDefault();
			var formData = $('form#login').serializeObject();
			console.log(formData);
			var nodeTip = $(this.el).find('.tip');
			nodeTip.hide();

			myUtil.login(formData, function(err, res) {
				console.log(res);
				if (err) return nodeTip.text(err).show();
				if (res.errCode !== 0) return nodeTip.text(res.errMsg).show();

				// all sucess;
				console.log('succ');
				window.location.href = "#forum/thread";
			});
		},

		doLogin2: function(event) {
			event.preventDefault();
			var formData = $('form.FormAbc').serializeObject();
			console.log(formData);
			var nodeTip = $(this.el).find('.tip');
			nodeTip.hide();

			myUtil.login(formData, function(err, res) {
				console.log(res);
				if (err) return nodeTip.text(err).show();
				if (res.errCode !== 0) return nodeTip.text(res.errMsg).show();

				// all sucess;
				console.log('succ');
				window.location.href = "#module/thread";
			});
		},


		toRegister: function(event) {
			window.location.href = "#module/login/register.js";
		}

	});
});